package com.hue.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQTopicConfig {
    private static final String topic1 = "topic.message";
    private static final String topic2 = "topic.messages";

    //创建两个消息队列
    @Bean
    public Queue queue1(){
        return new Queue(topic1);
    }

    @Bean
    public Queue queue2(){
        return new Queue(topic2);
    }

    //创建一个topic交换器
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topicExchange");
    }

    //将名为topic.message消息队列绑定到交换器上
    @Bean
    public Binding binding1(Queue queue1,TopicExchange topicExchange){
        return BindingBuilder.bind(queue1).to(topicExchange).with(topic1);
    }

    //将符合topic.#的消息队列绑定到交换器上
    @Bean
    public Binding binding2(Queue queue2,TopicExchange topicExchange){
        return BindingBuilder.bind(queue2).to(topicExchange).with("topic.#");
    }
}
